package com.cdie.myschool.domain.entity;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 
 * @TableName library_pass_record
 */
@Data
@NoArgsConstructor
public class LibraryPassRecord implements Serializable {
    @TableField(exist = false)
    private String uniqueId;
    /**
     * 主键
     */
    @TableId(type= IdType.AUTO)
    private Long passId;

    /**
     * 学年学期id
     */
    private Long semesterId;

    /**
     * 人员编码
     */
    private Long userId;

    /**
     * 进入时间
     */
    private Date entryTime;

    /**
     * 离开时间
     */
    private Date departureTime;

    /**
     * 在管时长
     */
    private Integer stayTime;

    /**
     * 进出类型(1:进2：出)
     */
    @TableField(exist = false)
    private Byte passType;

    /**
     * 时间戳
     */
    private Date timestamp;

    private static final long serialVersionUID = 1L;

    public LibraryPassRecord(LibraryPassRecordOld source) {
        this.uniqueId = source.getId();
        this.userId = Long.parseLong(source.getRybm());
        if(("1").equals(source.getJclx())){
            this.setEntryTime(DateUtil.
                    parse(source.getTxsj(),"yyyyMMddHHmmss"));
        }else{
            this.setDepartureTime(DateUtil.parse(source.getTxsj(),"yyyyMMddHHmmss"));
        }
        this.passType = Byte.parseByte(source.getJclx());
        if(source.getTstamp() !=null ){
            this.timestamp = DateUtil.parse(source.getTstamp(),"yyyyMMddHHmmss");
        }

    }


    public LibraryPassRecord setStayTimeForOutRecord(LibraryPassRecord next, Long minutes){
        this.setStayTime(Math.toIntExact(minutes));
        if(("1").equals(next.getPassType())){
            this.setEntryTime(next.entryTime);
        }else{
            this.setDepartureTime(next.getDepartureTime());
        }
        return this;
    }

}